package org.example.controller;

import org.example.beans.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.Duration;

@RestController
public class RedisController {
    @Autowired
    private RedisTemplate<String, User> template;

    @RequestMapping("put")
    public boolean put() {
        User user = new User();
        user.setId("1");
        user.setName("name");
        template.opsForValue().set("user", user, Duration.ofSeconds(30));
        return true;
    }

    @RequestMapping("get")
    public User get() {
        User user = template.opsForValue().get("user");
        return user;
    }
}
